﻿using System;
using System.Numerics;
/*
  Write a program that calculates for given N how many trailing
  zeros present at the end of the number N!.
  Examples:
	N = 10  N! = 3628800  2
	N = 20  N! = 2432902008176640000  4
  Does your program work for N = 50 000?
  Hint: The trailing zeros in N! are equal to the number of its prime divisors of value 5. Think why!
 */

class FactorielNTrailingZeros
{
    static void Main(string[] args)
    {
        
        
        Console.Write("Enter N: ");
        uint n = UInt32.Parse(Console.ReadLine());

        //dumm way

        //BigInteger nFactiorial = 1;
        //for (uint i = n; i > 0; i--)
        //{
        //    nFactiorial *= i;
        //}
        //Console.WriteLine("N! = {0}", nFactiorial);

        //int trailingZeroes = 0;
        //while (nFactiorial%10 == 0)
        //{
        //    nFactiorial /= 10;
        //    trailingZeroes++;
        //}
        //Console.WriteLine("Trailing zeros: {0}", trailingZeroes);


        //smart way 

        uint trailingZeroes2 = 0;
        for (uint i = 5; i <= n; i *= 5)
        {
            trailingZeroes2 +=  n/i;
            
        }

        Console.WriteLine("Trailing zeros the smart way: {0}", trailingZeroes2);
    }
}

